import {LineEdit, ScrollView, StandardTableView, Button, TextEdit} from "std-widgets.slint";

export component DaltonMain inherits Window {
    init => {
        input.focus()
    }
    callback calc(string);
    in-out property <[[StandardListViewItem]]> list: [];
    title: "Dalton";
    icon: @image-url("res/icon-small.png");
    min-height: 600px;
    default-font-size: 16px;
    default-font-family: "Consolas";
    always-on-top: true;
    VerticalLayout {
        padding: 16px;
        spacing: 4px;
        Rectangle {
            HorizontalLayout {
                spacing: 4px;
                input := LineEdit {
                    input-type: InputType.text;
                    placeholder-text: "input formula";
                    accepted => {
                        calc(input.text);
                        input.select-all();
                        table.set-current-row(table.rows.length - 1);
                    }
                }

                Button {
                    text: "Calc";
                    clicked => {
                        calc(input.text);
                        input.select-all();
                        table.set-current-row(table.rows.length - 1);
                    }
                }
            }
        }

        Rectangle {
            table := StandardTableView {
                width: 100%;
                height: 100%;
                columns: [{ title: "Formula" }, { title: "Mw" }];
                rows: root.list;
            }
        }
    }
}
